goog.provide('GLL.Sprite');

goog.require('lime');
goog.require('lime.Sprite');
goog.require('GLL.Sprite.Anim');

//----------------------------------------------------
// sprt = new GLL.Sprite()
//	.addAnim('footman_walk.bmp', 500, 20, 6).
//	.addAnim('footman_run.bmp', 500, 20, 6);
//
// sprt.setAnim("footman_walk.bmp");
GLL.Sprite = function() 
{
	lime.Sprite.call(this);
	this._Anims = [];
	this._nowAnim = null;
	this._100pps = 0; //100pixels per second

};

goog.inherits(GLL.Sprite, lime.Sprite);

GLL.Sprite.prototype.addAnim = function(name, file, width, height, key_x, key_y, ppl, spl)
{
	anim = new GLL.Sprite.Anim(file, width, height, key_x, key_y, ppl/100, spl);
	this._Anims[name] = anim;
	return this;
};

GLL.Sprite.prototype.setAnim = function(name)
{
	anim = this._Anims[name];
	if(!anim) return;
	if(this._nowAnim)
	{
		this._nowAnim.stop();
	}
	this.setSize(anim._frameWidth, anim._frameHeight);
	anim.addTarget(this);
	anim.play();
	this._nowAnim = anim;
	this._nowAnim.setSpeed(this._100pps);
};

GLL.Sprite.prototype.runAction = function(action)
{
	if(this._nowAnim)
	{
		this._100pps = 1 / action.speed_;
		this._nowAnim.setSpeed(this._100pps);
	}
	action.addTarget(this);
	action.play();
	
};